package graphSample;

import java.util.HashMap;

import core.Entity;
import core.Graph;
import core.Process;

/**
 * It is a graph simulating the drink machine
 * Consumers can deposit some money and get two kinds of drinks
 * value 15 dollars and 20 dollars
 * @author zhang chao gui
 *
 */
public class Automata {
	static public Graph getGraph(){
		Graph g = new Graph("Automata");
		
		Entity e1 = new Entity(g, "VenderMachine");
		e1.addVariable("$money","INT"); //dollars
		e1.addVariable("$num1","INT");//drink1
		e1.addVariable("$num2","INT");//drink2
		
		
		/*
		 * Deposit 5 dollars into the drink machine
		 * while the total money is less than 15 dollars
		 */
		Process p1 = new Process(g, "Deposit 5 dollars", "$money <= 95");
		p1.addEntityIn(e1); p1.addEntityOut(e1);
		p1.addEvalItem("$money=$money+5");
		/*
		 * Deposit 10 dollars into the drink machine
		 * while the total money is less than 10 dollars
		 */
		Process p2 = new Process(g, "Deposit 10 dollars", "$money <= 90");
		p2.addEntityIn(e1); p2.addEntityOut(e1);
		p2.addEvalItem("$money=$money+10");

		/*
		 * Get a drink A from the machine
		 * while the total money equals 15 dollars
		 */
		Process p3 = new Process(g, "Get  drink A", "$money >= 15");
		p3.addEntityIn(e1); p3.addEntityOut(e1);
		p3.addEvalItem("$money=$money-15");
		p3.addEvalItem("$num1=$num1+1");
		/*
		 * Get a drink B from the machine
		 * while the total money equals 20 dollars
		 */
		Process p4 = new Process(g, "Get a drink2", "$money >= 20");
		p4.addEntityIn(e1); p4.addEntityOut(e1);
		p4.addEvalItem("$money$money-20");
		p4.addEvalItem("$num2=$num2+1");
			
		//Add token in e1
		HashMap<String,String> token;
		for(int i=0;i<10000;i++){
			token = new HashMap<String,String>();
			token.put("$money", String.valueOf(0));
			token.put("$num1", String.valueOf(0));
			token.put("$num2", String.valueOf(0));
			e1.addToken(token);
		}
		
		return g;
	}
}
